package com.hejjon.knowledgebase.service.impl;

import com.hejjon.knowledgebase.entity.RepairRecord;
import com.hejjon.knowledgebase.service.DataStatisticService;
import com.hejjon.knowledgebase.service.RepairRecordService;
import com.hejjon.knowledgebase.vo.RepairRecordStatisVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author: caoshi
 * @date: 2022-12-19 16:08:22
 * @since: 1.0
 */
@Service
public class DataStatisticServiceImpl implements DataStatisticService {

    @Resource
    private RepairRecordService repairRecordService;

    @Override
    public List<RepairRecordStatisVO> getRepairRecordStatis() {
        Map<Integer, List<RepairRecord>> recordByStateMap = repairRecordService.getRecordByState();
        List<RepairRecordStatisVO> result = new ArrayList<>();
        for (Map.Entry<Integer, List<RepairRecord>> entry : recordByStateMap.entrySet()) {
            RepairRecordStatisVO vo = new RepairRecordStatisVO();
            vo.setState(entry.getKey());
            vo.setCount(entry.getValue().size());
            result.add(vo);
        }
        return result;
    }
}
